//
//  EaTabBarController.m
//  EaWeibo
//
//  Created by xalo on 16/7/8.
//  Copyright © 2016年 Eason. All rights reserved.
//

#import "DZZTabBarController.h"
#import "DZZNavigationController.h"

@interface DZZTabBarController ()

@end

@implementation DZZTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
[self setChildViewController];
    
//    自定义tabBar
    DZZTabBar *tabBar = [[DZZTabBar alloc]initWithFrame:self.tabBar.frame];
//    利用KVC赋值改变属性
    [self setValue:tabBar forKey:@"tabBar"];
    
}

- (void)setChildViewController{
    //    改变文字的颜色
    UITabBarItem *item = [UITabBarItem appearance];
    NSMutableDictionary *att = [NSMutableDictionary dictionary];
    att[NSForegroundColorAttributeName] = [UIColor orangeColor];
    [item setTitleTextAttributes:att forState:UIControlStateSelected];
    
    
    
    //    首页
    DZZHomeViewController *home = [[DZZHomeViewController alloc]initWithNibName:@"DZZHomeViewController" bundle:nil];
    
    [self setChildViewControllerWithController:home image:[UIImage imageNamed:@"home1"] selectedImage:[UIImage imageNamed:@"home2"] title:@"首页"];
    home.view.backgroundColor = [UIColor whiteColor];
   
    
    //    目的地
    
    DZZDestinationViewController *message = [[DZZDestinationViewController alloc]init];
    
    [self setChildViewControllerWithController:message image:[UIImage imageNamed:@"des1"] selectedImage:[UIImage imageNamed:@"des2"] title:@"目的地"];
    

    
    //    发现
    DZZDiscoverViewController *discover = [[DZZDiscoverViewController alloc]init];
    
    [self setChildViewControllerWithController:discover image:[UIImage imageNamed:@"dis1"] selectedImage:[UIImage imageNamed:@"dis2"] title:@"发现"];
    discover.view.backgroundColor = [UIColor purpleColor];

    
    //    我
    
    DZZMyViewController *my = [[DZZMyViewController alloc]init];
    
    [self setChildViewControllerWithController:my image:[UIImage imageNamed:@"my3"] selectedImage:[UIImage imageNamed:@"my4"] title:@"我的"];
    my.view.backgroundColor = [UIColor yellowColor];
}
- (void)setChildViewControllerWithController:(UIViewController *)controller image:(UIImage *)image selectedImage:(UIImage *)selectedImage title:(NSString *)title{
    
    controller.title = title;
    controller.tabBarItem.image = image;
    
    controller.tabBarItem.image = image;
    controller.tabBarItem.selectedImage = selectedImage;
    UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:controller];
    
    [self addChildViewController:navi];
    
}

@end
